{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post" enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row rowSelect">
    <label for="user_id" class="col-sm-2 col-form-label">用户</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="user_id" id="user_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择用户">
            <option value=""></option>
            {foreach name='user_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.user_id==$item.id}selected{/if}>
        {$item.username}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#user_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="from_id" class="col-sm-2 col-form-label">来自</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="from_id" id="from_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择来自">
            <option value=""></option>
            {foreach name='from_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.from_id==$item.id}selected{/if}>
        {$item.id}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#from_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowSelect">
    <label for="article_id" class="col-sm-2 col-form-label">文章</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <select name="article_id" id="article_id" class="form-control select2bs4 fieldSelect" data-placeholder="请选择文章">
            <option value=""></option>
            {foreach name='article_list' id='item'}
    <option value="{$item.id}" {if isset($data) && $data.article_id==$item.id}selected{/if}>
        {$item.title}
    </option>
{/foreach}
        </select>
    </div>

    <script>
        $('#article_id').select2({
            theme: 'bootstrap4'
        });
    </script>
</div>
<div class="form-group row rowText">
    <label for="title" class="col-sm-2 col-form-label">标题</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="title" name="title" value="{$data.title|default=''}" placeholder="请输入标题" type="text" class="form-control fieldText">
    </div>
</div>
<div class="form-group row rowText">
    <label for="content" class="col-sm-2 col-form-label">内容</label>
    <div class="col-sm-10 col-md-4 formInputDiv">
        <input id="content" name="content" value="{$data.content|default=''}" placeholder="请输入内容" type="text" class="form-control fieldText">
    </div>
</div>

                    </div>
                    <!-- 表单底部 -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create" name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
                'user_id': {
                required: true,

    },
    'from_id': {
                required: true,

    },
    'article_id': {
                required: true,

    },
    'title': {
                required: true,

    },
    'content': {
                required: true,

    },

        },
        messages: {
                'user_id': {
               required: "用户不能为空",

    },
    'from_id': {
               required: "来自不能为空",

    },
    'article_id': {
               required: "文章不能为空",

    },
    'title': {
               required: "标题不能为空",

    },
    'content': {
               required: "内容不能为空",

    },

        }
    });
</script>
{/block}